#include "Screen.h"

using namespace SolidityEngine;

Screen::Screen()
{
    //ctor
}

Screen::~Screen()
{
    //dtor
}

std::list<Screen::Resolution> Screen::Resolutions(){
    SDL_Rect** modes=NULL;

    modes=SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_HWSURFACE);

    std::list<Resolution> modelist;
    if(modes==(SDL_Rect**)NULL || modes==(SDL_Rect**)-1){
        return modelist;
    }
    for(int i=0; modes[i]; ++i){
        modelist.push_back(Resolution(modes[i]->w,modes[i]->h,true));
    }
    return modelist;
}

Screen::Resolution Screen::CurrentResolution(){
    return Resolution(SDL_GetVideoInfo()->current_w,SDL_GetVideoInfo()->current_h, _fullscreen);
}

Screen::Resolution& Screen::RequestedResolution(){
    return _requestedres;
}

int Screen::Width(){
    const SDL_VideoInfo* info = SDL_GetVideoInfo();
    if(info!=NULL)
    {
        return SDL_GetVideoInfo()->current_w;
    }
    return 0;
}

int Screen::Height(){
    const SDL_VideoInfo* info = SDL_GetVideoInfo();
    if(info!=NULL)
    {
        return SDL_GetVideoInfo()->current_h;
    }
    return 0;
}

Color32 Screen::ClearColor(){
    return _clearcolor;
}

void Screen::SetResolution(Screen::Resolution res, const Color32& col){
    _requestedres=res;
    _clearcolor=col;
    SDL_Surface* surf=SDL_GetVideoSurface();
    if(surf!=NULL){
        if(res.FullScreen()){
            surf=SDL_SetVideoMode(res.Width(), res.Height(), 32, SDL_FULLSCREEN|SDL_HWSURFACE|SDL_DOUBLEBUF);
            _fullscreen=true;
        }
        else{
            surf=SDL_SetVideoMode(res.Width(), res.Height(),32,SDL_HWSURFACE|SDL_DOUBLEBUF);
            _fullscreen=false;
        }
    }
}

void Screen::SetResolution(Screen::Resolution res){
    Screen::SetResolution(res,_clearcolor);
}

Screen::Resolution Screen::_requestedres=Screen::Resolution(0,0,false);
Color32 Screen::_clearcolor=Color32(0,0,0);
bool Screen::_fullscreen=false;


